package com.example.design.filter.enums;

import com.example.design.ServiceException;
import com.example.design.DataDictionary;

/**
 * @author shishaopeng
 */
public enum ScheduleTagEnum implements DataDictionary {
    //
    LEAVE("leave", "请假"),
    NO_MON("no_mon", "周一不上班"),
    NO_TUES("no_tues", "周二不上班"),
    NO_WED("no_wed", "周三不上班"),
    NO_THUR("no_thur", "周四不上班"),
    NO_FRI("no_fri", "周五不上班"),
    NO_SAT("no_sat", "周六不上班"),
    NO_SUN("no_sun", "周日不上班"),
    NO_DAY("no_day", "不能早班"),
    NO_NIGHT("no_night", "不能晚班");


    public static ScheduleTagEnum getByDictCode(String dictCode) {
        for (ScheduleTagEnum tagEnum : ScheduleTagEnum.values()) {
            if (tagEnum.getDictCode().equalsIgnoreCase(dictCode)) {
                return tagEnum;
            }
        }
        throw new ServiceException("未知的排班标签");
    }

    /**
     * 每周从周一(1)开始
     */
    public static ScheduleTagEnum getByDayOfWeek(int dayOfWeek) {
        switch (dayOfWeek) {
            case 1:
                return NO_MON;
            case 2:
                return NO_TUES;
            case 3:
                return NO_WED;
            case 4:
                return NO_THUR;
            case 5:
                return NO_FRI;
            case 6:
                return NO_SAT;
            case 7:
                return NO_SUN;
            default:
                throw new ServiceException("unknown day of week value: " + dayOfWeek);
        }
    }

    private final String dictCode;
    private final String dictName;

    ScheduleTagEnum(String dictCode, String dictName) {
        this.dictCode = dictCode;
        this.dictName = dictName;
    }

    @Override
    public String getDictCode() {
        return dictCode;
    }

    @Override
    public String getDictName() {
        return dictName;
    }

    @Override
    public String getDictItemDesc() {
        return dictCode;
    }

    @Override
    public int intValue() {
        return ordinal();
    }
}
